package comment;

import utils.JdbcUtils;

import java.util.Date;
import java.util.List;
import java.util.Map;

public class Comment {
    public static int sum= JdbcUtils.JdbcQuery("SELECT * FROM comment").size();
    public static void jssum(){
        sum=JdbcUtils.JdbcQuery("SELECT * FROM comment").size();  //注册文章数目统计
    }
    public static String sql_addComment="INSERT INTO comment values (?,?,?,?,?,?,?,?);";
    public static String sql_deleteComment="DELETE FROM comment WHERE comment_id = ?";
    public static String sql_deleteComment_class="DELETE FROM comment WHERE comment_name = ?";
    public static String sql_queryComment="SELECT * FROM comment WHERE comment_id = ? ";
    public static String sql_queryComment_sum="SELECT * FROM comment WHERE comment_name = ? ";
    public static String sql_updataCommentText="UPDATE comment SET comment_text = ? WHERE comment_id = ?";
    public static String sql_updataCommentTime="UPDATE comment SET comment_updata = ? WHERE comment_id = ?";
    public static boolean comment_same(String name){
        return !JdbcUtils.JdbcQuery("SELECT comment_name FROM comment WHERE comment_name = "+name).isEmpty();
    }
    public static void idChange(){
        String sql = "SELECT * FROM comment ORDER BY comment_id ASC";
        List<Map<String, Object>> rs = JdbcUtils.JdbcQuery(sql);
        int newId = 1;
        for(Map<String,Object> map : rs){
            for(String key : map.keySet()) {
                if (key.equals("comment_id")){
                    int oldId = (int) map.get(key);
                    String updateSql = ("UPDATE comment SET comment_id = " + newId +" WHERE comment_id = " + oldId);
                    JdbcUtils.JdbcUpdate(updateSql);
                    newId++;
                }
            }
        }
    }
}
